function process_sensaris_logfiles(log_directory, output_directory)
% SENSARIS - Process log files from log_directory and generates
%   *.mat files in output_directory.
%
%   A/YYMMDD.LOG  =>  YYMMDD_A.mat
%
% Usage:
%   values=parse_logfile('100129.A.LOG');
%

%% cleaning

%% global variables
global BASE_DIRECTORY;
global NOX_SCALING;
global COX_SCALING;
global HUM_SCALING;
global TEMP_SCALING;
global NOISE_SCALING;
global BATT_SCALING;
global DEVICE_IDS;

ndevices = size(DEVICE_IDS,2);
for i=1:ndevices
    id = char(DEVICE_IDS(i));
    files_dir = strcat(log_directory, '/', id);
    disp(['Processing device:', files_dir]);
    files = dir(strcat(files_dir, '/*.LOG'));
    nfiles = size(files,1);
    for j=1:nfiles
        filename = files(j).name;
        file_fullname = strcat(files_dir,'/', filename);
        disp(['Parsing ...:', file_fullname]);
        values=parse_sensaris_logfile(file_fullname);
        matfile_fullname = strcat(output_directory,'/', filename, '_', id, '.mat');
        disp(['converted to:', matfile_fullname]);
        save(matfile_fullname, 'values');
    end
    
end
% %    files_to_process=[files_to_process; {files(i).name}];
%     filename = files(i).name;
%     disp(['Processing ...:', filename]);
% %     values=parse_logfile(filename);
% %     matfilename = strcat(filename,'.mat');
% %     save(matfilename, 'values');
% end
% 
